<%@page import="javax.swing.plaf.basic.BasicInternalFrameTitlePane.SystemMenuBar"%>
<%@page import="vo.boardVO"%>
<%@page import="dto.boardDTO"%>
<%@page import="java.util.ArrayList" %>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Calendar"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>List</title>
<link rel="stylesheet" href="../css/board.css">
<script src = '../js/board.js'></script>
</head>
<body>
<jsp:useBean id="vo" class="vo.boardVO" scope="page"/>
<jsp:setProperty property="*" name="vo"/>

<%
	boardVO bvo = vo;

	int category = Integer.parseInt(request.getParameter("category"));
	String m_id = (String)session.getAttribute("sessionMid");
	bvo.setM_id(m_id);
	bvo.setB_category(category);
	
	
	boardDTO dto = new boardDTO(bvo);
	dto.e_num();		// m_id를 통해서 사원의 번호를 db에서 얻어옴

	ArrayList<boardVO> al = dto.list();
	
	switch(category){
	case 1:
		out.println("<p><input type='image' src='../images/m_title_notice.png'/>");
		break;
	case 2:
		out.println("<p><input type='image' src='../images/m_title_event.png'/>");
		break;
	case 10:
		out.println("<p><input type='image' src='../images/m_title_freeboard.png'/>");
		break;
	case 101:
		out.println("<p><input type='image' src='../images/m_title_club_golf.png'/>");
		break;
	case 102:
		out.println("<p><input type='image' src='../images/m_title_club_moutain.png'/>");
		break;
	case 103:
		out.println("<p><input type='image' src='../images/m_title_club_soccer.png'/>");
		break;
	}
%>

<div id = 'wrab'>
	<form name = 'hiddenFrm' method='post'>
		 	<input type='hidden' name="nowPage"/>
		 	<input type='hidden' name='find' />
		 	<input type='hidden' name='b_number'/>
		 	<input type='hidden' name='b_category' value="<%=vo.getB_category()%>"/>
		 	<input type='hidden' name='m_id' value="<%=vo.getM_id()%>"/>
	 		<input type='hidden' name='e_number' value="<%=vo.getE_number() %>"/>
	</form>
	
	<p/>
	<div id = 'board_list_title'>
		<div class='board_list_b_number'>글번호</div>
		<div class='board_list_b_title'>제&nbsp;&nbsp;&nbsp;&nbsp;목</div>
		<div class='board_list_e_name'>글쓴이</div>
		<div class='board_list_b_date'>작성일</div>
		<div class='board_list_b_viewno'>조회수</div>
		<div class='board_list_b_image'>파&nbsp;&nbsp;&nbsp;일</div>
	</div>
	
<%
	for(int a=0; a<al.size(); a++){
	boardVO v = al.get(a);
	//out.println("들여쓰기" + (v.getB_indent()));
%>
 <div class="board_list_items">
		<div class='board_list_b_number'><%=v.getB_number()%></div>
		
		<%if(v.getB_group()==v.getB_number()){ %>
			<div class="board_list_b_title">
				<a href = '#' onclick="goView(<%=dto.getNowPage()%>,<%=v.getB_number()%>)">
					<% 	if(v.getB_title().length()>20){
						String title = v.getB_title().substring(0, 20); %>
			    		<%=title%>...
					<%} else {%>
						<%=v.getB_title()%>
					<%}%>
				<% 	String date2 = (String)v.getB_date();
				 		String date3 = date2.substring(0, 10);
				   		String timeStamp = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
					if(date3.equals(timeStamp)){%>
							<div id='board_list_b_title3'><img alt="" src="../images/icon_new.gif"> </div>
				<%}%>
				<% if(v.getB_viewNo()>=25){%>
							<div id='board_list_b_title4'><img alt="" src="../images/icon_hot.gif"> </div>
				<%}%>	
				</a>
			</div>
		<%}else{%>
			<div class="board_list_b_title">
				<a href="#" onclick="goView(<%=dto.getNowPage() %>, '<%=v.getB_number() %>')">
					<% for(int j=0; j<=(v.getB_deep()); j++){ %>
					&nbsp;
					<%} %>
					<div id='board_list_b_title1'><img alt="" src="../images/icon_reply.png"> </div>
					<% if(v.getB_title().length()>20){
							String title = v.getB_title().substring(0, 20); %>
					    	<div id='board_list_b_title2'><%=title%>...</div>
						<%} else {%>
							<div id='board_list_b_title2'><%=v.getB_title()%></div>
						<%} %>
				<% 	String date2 = (String)v.getB_date();
				 		String date3 = date2.substring(0, 10);
				   		String timeStamp = new SimpleDateFormat("yyyy-MM-dd").format(Calendar.getInstance().getTime());
					if(date3.equals(timeStamp)){%>
							<div id='board_list_b_title3'><img alt="" src="../images/icon_new.gif"> </div>
				<%}%>
				<% if(v.getB_viewNo()>=25){%>
							<div id='board_list_b_title4'><img alt="" src="../images/icon_hot.gif"> </div>
				<%}%>		
				</a>

			</div>	
		<%}
		%>
				
		
		<div class='board_list_e_name'><%=v.getE_name()%></div>
		<div class='board_list_b_date'>
			<% 	String date = (String)v.getB_date();
				if(date.length()>10){
				String date1 = date.substring(0, 10); %>
		    	<%=date1%>
			<%} else {%>
				<%=v.getB_date()%>
			<%}%>
		</div>
		<div class='board_list_b_viewno'><%=v.getB_viewNo()%></div>
		<div class='board_list_b_fileUrl'>		
		<% if(v.getB_fileUrl()!= null){%>
			<img alt="" src="../images/file.png">	
			 <% if(v.getB_fileUrl().length()>12){
				String image = v.getB_fileUrl().substring(0, 12); %>
		    	 <%=image%>..
			<%}else{%>
				<%=v.getB_fileUrl()%> 
			<%}%>	
		<%}else{%>
		<%}%>
		</div>
	</div>	
<%}%>	
<p>
<!-- 페이징 부분 -->
<div id = 'list_page' align="center">
		<% if(dto.getNowPage()==1){%>
		[처음으로]
		<%}else{%><a href='#' onclick='goPage(1)'>[처음으로]  </a>
		<%}%>
		
	<% if(dto.getNowBlock()==1){%>
		[이전으로]
		<%}else{%><a href="#" onclick='goPage(<%=dto.getStartPage()-1 %>)'> [이전으로] </a>
		<%} %>	
	<%	
	int i=0;
	for(i = dto.getStartPage(); i<=dto.getEndPage(); i++){%>
	<a href= "#" onclick = "goPage(<%= i %>)"><%= i %></a>
	<%} %>
	<% if(dto.getNowBlock()==dto.getTotBlock()){%>
		[다음으로]
		<%}else{%><a href= '#' onclick = "goPage(<%=i %>)">  [다음으로] </a>
		<%} %>
	
	<% if(dto.getNowPage()==dto.getTotPage()){%>
		[맨끝으로]
		<%}else{%><a href= "#" onclick = "goPage(<%=dto.getTotPage() %>)">  [맨끝으로] </a>
		<%} %>	
	
</div>

<p>
<!-- 검색 부분  -->
	<div align="center">
		<form action="" name ='board_list_frm' method = 'post'>
			<div id='board_search'>
				<div id='board_search_text'><input type="text" name = 'find' value ="<%=vo.getFind()%>" size="20"/></div>
				<div id='board_search_button'> <input type="image" src="../images/button_blue_search.png" onclick="search(<%=vo.getB_category()%>)"/></div>
				<input type='hidden' name='b_category' value="<%=vo.getB_category()%>"/>
			</div>
		</form>
				<input type="image" src="../images/button_blue_write.png" value="새 글쓰기" id="btnInput" align="right"/>
	</div>
<p>	
</div>	
</body>
<script>listInit();</script>
</html>